package beautiful.butterfly.execute_engine;

import java.util.concurrent.Callable;

public abstract class CallableObject implements Callable {

    private volatile CallableContext callableContext;

    public void setCallableContext(CallableContext callableContext) {
        this.callableContext = callableContext;
    }

    public CallableContext getCallableContext() {
        return callableContext;
    }

    @Override
    public Object call() throws Exception {
        checkCallableContextIsNotNull();
        return doTask();
    }

    public Object doTask() throws Exception {
        return null;
    }

    public void checkCallableContextIsNotNull() {
        while (true) {
            if (this.callableContext != null) {
                break;
            }
        }
    }
}
